/*
 * @Date: 2023-03-14 13:09:41
 * @LastEditors: Chuying
 * @LastEditTime: 2023-04-03 14:11:23
 * @Description:
 */
/**
 * 应用程序入口文件
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { join } from 'path';
import { NestExpressApplication } from '@nestjs/platform-express';
import { Response } from 'src/common/response';
import { HttpFilter } from 'src/common/filter';
import { ValidationPipe } from '@nestjs/common';

import { IndexMiddleWare } from 'src/middleware/index/index.middleware';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
// import { UserInfo } from './modules/account/user/entities/user_info.entity';
// import { ResponseDto } from './decorator/api-paginated-response.decorator';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  //   app.setGlobalPrefix('api'); // 全局前缀

  app.useStaticAssets(join(__dirname, '../public'), {
    prefix: '/static',
  });

  app.useGlobalInterceptors(new Response());
  app.useGlobalFilters(new HttpFilter());
  app.useGlobalPipes(new ValidationPipe());

  // 全局中间件
  app.use(IndexMiddleWare);

  const config = new DocumentBuilder()
    // .addBearerAuth()
    .setTitle('大吉大利大前端项目')
    .setDescription('详细描述')
    .addServer('http://localhost:3011', '开发环境')
    .addServer('http://124.220.15.206:3011', '测试环境')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, config, {
    // extraModels: [UserInfo, ResponseDto],
  });
  SwaggerModule.setup('api', app, document);
  app.enableCors(); // 允许跨域
  await app.listen(3011);
}
bootstrap();
